package com.allwees.bs.c.module.order.mq.listener;

import com.allwees.bs.c.module.payment.req.PaymentCaptureReq;
import com.allwees.bs.c.module.payment.service.IPaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RabbitListener(queues = "q.C.Order.PaypalCapture", errorHandler = "payMqErrorHandler")
public class PaypalCaptureListener {

    @Autowired
    private IPaymentService paymentService;

    @RabbitHandler
    public void on(PaymentCaptureReq req) {

        long start = System.currentTimeMillis();

        paymentService.capture(req);

        log.info("paypal capture listener [orderUuid:{}], time: {}ms", req.getOrderUuid(), (System.currentTimeMillis() - start));
    }
}
